import axios from 'axios'
import utils from '../../common/util'
axios.defaults.withCredentials = true // 跨域
axios.defaults.timeout = 10000

export default {
  // get请求
  requestGet (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.get(url, {
        headers: {
          'Authorization': utils.getToken()
        },
        params
      }).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // get请求不带参数
  requestQuickGet (url) {
    return new Promise((resolve, reject) => {
      axios.get(url, {
        headers: {
          'Authorization': utils.getToken()
        }
      }).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  },
  // post请求
  requestPost (url, params = {}) {
    return new Promise((resolve, reject) => {
      axios.post(url, params, {
        headers: {
          'Authorization': utils.getToken()
        }
      }).then(res => {
        resolve(res.data)
      }).catch(error => {
        reject(error)
      })
    })
  }
}
